﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Gift.WebApp;
using System.Data;
using System.Threading;

using Gift.DAL;
using Gift.Model;

public partial class cn_Mail :BasePage
{
    // Fields

   

    // Methods
    protected void btnSend_Click(object sender, EventArgs e)
    {
        SendMailMessage message = new SendMailMessage();
        string[] strArray = new string[] { "zyh_100@126.com" };
        message.subject = base.Request.Form["sobject"];
        message.body = base.Request.Form["body"];
        message.html = true;
        DataTable allEnabledMail = BaseFactory.theMail.GetAllEnabledMail();
        Random random = new Random();
        for (int i = 0; i < strArray.Length; i++)
        {
            message.mailTo = strArray.GetValue(i).ToString();
            int num2 = random.Next(allEnabledMail.Rows.Count - 1);
            DataRow row = allEnabledMail.Rows[num2];
            message.from = row["fromAddress"].ToString();
            message.fromName = row["fromName"].ToString();
            message.mailDomain = row["mailDomain"].ToString();
            message.mailDomainPort = Convert.ToInt32(row["mailDomainPort"]);
            message.mailServerUserName = row["mailServerUserName"].ToString();
            message.mailServerPassWord = row["mailServerPassWord"].ToString();
            message.SendMailEvent += new SendMailMessage.SendMailHandler(this.SendMain);
            new Thread(new ThreadStart(message.Send)).Start();
        }
        Thread.Sleep(100);
        base.ClientScript.RegisterStartupScript(base.GetType(), "ms", "alert('发送成功！');", true);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected void SendMain()
    {
    }

}